﻿using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace Api.Shared.Sugar.Sqlite
{
    public class SqliteClientService : ISugarClientService
    {
        private readonly ISqlSugarService service;
        public SqliteClientService([FromKeyedServices(nameof(SqlName.sqlite))] ISqlSugarService service)
        {
            this.service = service;
        }

        public SqlSugarClient Db
        {
            get => new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = service.ConnectionStr,
                DbType = DbType.Sqlite,         //必填, 数据库类型
                //DbType = DbType.MySql,
                IsAutoCloseConnection = true,       //默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作
                InitKeyType = InitKeyType.Attribute    //默认SystemTable, codefist需要使用Attribute
            });
        }
    }
}
